package com.example.administrator.youlu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public abstract class MyBaseAdapter<T> extends BaseAdapter {


    protected List<T> mData = new ArrayList<>();
    protected Context mContext;
    protected LayoutInflater layoutInflater;

    public MyBaseAdapter(Context mContext) {
        this.mContext = mContext;
        this.layoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public T getItem(int i) {
        return mData.get(i);
    }



    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public abstract View getView(int i, View view, ViewGroup viewGroup);

    /**
     * @param datas
     * @param isClean
     */
    public void addDatas(List<T> datas,boolean isClean ){
        if (isClean){
            mData.clear();
        }
        if (datas!=null)
            mData.addAll(datas);
        notifyDataSetChanged();
    }

    /**
     *
     */
    public void removeDatas(){
        mData.clear();
        notifyDataSetChanged();
    }

    /**
     * @param t
     */
    public void removeDatas(T t){
        mData.remove(t);
        notifyDataSetChanged();
    }

    /**
     * @return
     */
    public List<T> getmData() {
        return mData;
    }

}
